package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import pojo.League;
import transfer.JoinLeagueData;
import util.Utils;
import widget.MyButtonWidget;
import callback.BackToLobbyCallback;
import client.Client;

public class JoinLeagueForm extends ChessOnlineView {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1051365486675440659L;

	public static final String[] SCORE_BET = {"10", "20", "30"};
	
	private League mLeague;
	private MyButtonWidget mBackBtn;
	//private ChessOnlineRoom room = null;

	public JoinLeagueForm(Client mainScreen, League league) {
		super(mainScreen);
		this.mLeague = league;
		
		this.setSize(500, 250);
		GridBagLayout gridbag = new GridBagLayout();
		setLayout(gridbag);
		GridBagConstraints c = new GridBagConstraints();
		
		JButton createCmd = new JButton("Join");
		c.fill = GridBagConstraints.HORIZONTAL;
		c.weightx = 0.5;
		c.gridx = 0;
		c.gridwidth = 2;
		c.gridy = 3;
		add(createCmd, c);
		
		JLabel questionLBL = new JLabel("Do you want to join the league?");
		questionLBL.setForeground(Color.cyan);
		c.fill = GridBagConstraints.HORIZONTAL;
		c.insets = new Insets(0,20,0,0);  //top padding
		c.ipady = 40;      //make this component tall
		c.weightx = 0.0;
		c.gridwidth = 0;
		c.gridx = 1;
		c.gridy = 0;
		add(questionLBL, c);
		
		createCmd.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {				
				//mMainScreen.createNewRoom(roomName, score);
				 //room = new ChessOnlineRoom(mMainScreen.getRoomIndex(), roomName, mMainScreen.getAcc(), null, score, false);
				
				 //mMainScreen.getmLobbyView().addRoom(room);
				//mMainScreen.addRoom(room);
				//mMainScreen.showRoomView(room);
//				ArrayList<ChessOnlineRoom> a = mMainScreen.getRooms().clone();
				
				Utils.saveLeagueId(mLeague.getLeagueId());
				mMainScreen.getCw().sendObject(new JoinLeagueData("Join League", mLeague.getLeagueId(), mMainScreen.getAcc()));
			}
		});
		
		mBackBtn = new MyButtonWidget(650, 450, "Resources/Images/back-icon.png", 
				"Resources/Images/back-icon.png", "", new BackToLobbyCallback(mMainScreen,null));
		this.add(mBackBtn);
		this.addMouseListener(mMyListener);
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		mBackBtn.paint(g);
	}
	
	private MouseListener mMyListener = new MouseAdapter() {
		public void mouseClicked(java.awt.event.MouseEvent e) {
			mBackBtn.onClick(e);
		};
	};


}
